package org.gdstash.ui.character;

import org.gdstash.character.GDChar;
import org.gdstash.ui.GDStashFrame;
import org.gdstash.ui.util.AdjustableTabbedPane;
import org.gdstash.ui.util.GDAbstractUpdateCharPane;
import org.gdstash.util.GDMsgFormatter;

import javax.swing.*;
import java.awt.*;

public class GDCharRiftNShrineTabbedPane extends AdjustableTabbedPane {
    private GDAbstractUpdateCharPane pnlNormal;
    private GDAbstractUpdateCharPane pnlElite;
    private GDAbstractUpdateCharPane pnlUltimate;
    private GDChar gdc;

    public GDCharRiftNShrineTabbedPane() {
        this.adjustUI();
    }

    @Override
    public void adjustUI() {
        Font fntTabbed = UIManager.getDefaults().getFont("TabbedPane.font");
        fntTabbed = fntTabbed.deriveFont((float) GDStashFrame.iniConfig.sectUI.fontSize);
        this.setFont(fntTabbed);
        final boolean vanilla = true;
        if (this.pnlNormal == null) {
            this.pnlNormal = new GDCharRiftNShrinePane(0);
        } else {
            this.pnlNormal.adjustUI();
        }
        if (this.pnlElite == null) {
            this.pnlElite = new GDCharRiftNShrinePane(1);
        } else {
            this.pnlElite.adjustUI();
        }
        if (this.pnlUltimate == null) {
            this.pnlUltimate = new GDCharRiftNShrinePane(2);
        } else {
            this.pnlUltimate.adjustUI();
        }
        if (this.getTabCount() == 0) {
            this.add(this.pnlNormal);
            this.add(this.pnlElite);
            this.add(this.pnlUltimate);
        }
        this.setTitleAt(0, GDMsgFormatter.getString(GDMsgFormatter.rbUI, "TXT_DIFF_NORMAL"));
        this.setTitleAt(1, GDMsgFormatter.getString(GDMsgFormatter.rbUI, "TXT_DIFF_ELITE"));
        this.setTitleAt(2, GDMsgFormatter.getString(GDMsgFormatter.rbUI, "TXT_DIFF_ULTIMATE"));
    }

    public void setChar(final GDChar gdc) {
        this.gdc = gdc;
        boolean rot = false;
        if (gdc != null && gdc.isRoTCampaign()) {
            rot = true;
        }
        if (rot) {
            if (this.pnlNormal instanceof GDCharRiftNShrinePane) {
                this.pnlNormal = new RoTRiftNShrinePane(0);
                this.pnlElite = new RoTRiftNShrinePane(1);
                this.pnlUltimate = new RoTRiftNShrinePane(2);
                this.removeAll();
                this.add(this.pnlNormal);
                this.add(this.pnlElite);
                this.add(this.pnlUltimate);
                this.setTitleAt(0, GDMsgFormatter.getString(GDMsgFormatter.rbUI, "TXT_DIFF_NORMAL"));
                this.setTitleAt(1, GDMsgFormatter.getString(GDMsgFormatter.rbUI, "TXT_DIFF_ELITE"));
                this.setTitleAt(2, GDMsgFormatter.getString(GDMsgFormatter.rbUI, "TXT_DIFF_ULTIMATE"));
            }
        } else if (this.pnlNormal instanceof RoTRiftNShrinePane) {
            this.pnlNormal = new GDCharRiftNShrinePane(0);
            this.pnlElite = new GDCharRiftNShrinePane(1);
            this.pnlUltimate = new GDCharRiftNShrinePane(2);
            this.removeAll();
            this.add(this.pnlNormal);
            this.add(this.pnlElite);
            this.add(this.pnlUltimate);
            this.setTitleAt(0, GDMsgFormatter.getString(GDMsgFormatter.rbUI, "TXT_DIFF_NORMAL"));
            this.setTitleAt(1, GDMsgFormatter.getString(GDMsgFormatter.rbUI, "TXT_DIFF_ELITE"));
            this.setTitleAt(2, GDMsgFormatter.getString(GDMsgFormatter.rbUI, "TXT_DIFF_ULTIMATE"));
        }
        this.pnlNormal.setChar(gdc);
        this.pnlElite.setChar(gdc);
        this.pnlUltimate.setChar(gdc);
    }

    public void updateChar(final GDChar gdc) {
        if (gdc == null) {
            return;
        }
        this.pnlNormal.updateChar(gdc);
        this.pnlElite.updateChar(gdc);
        this.pnlUltimate.updateChar(gdc);
    }
}
